﻿// <copyright file="GeneralTransform3D.cs" company="Axelerate Solutions S.A.">
// Copyright (c) Axelerate Solutions S.A.  All rights reserved.
// </copyright>

namespace Axelerate.Silverlight3D.Media.Media3D
{
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    /// <summary>
    /// File name: GeneralTransform3D.cs
    /// Company: Axelerate Solutions S.A.
    /// Created By: Daniel Rojas
    /// Created Date: 10/07/2008 15:27:00 h.
    /// Description: Provides generalized transformation support for 3-D objects.
    ///   <Modifications>
    ///   </Modifications>
    /// </summary>
    public abstract class GeneralTransform3D : Freezable, IFormattable 
    {
        #region Properties
        /// <summary>
        /// Gets the inverse transformation of this GeneralTransform3D, if possible.
        /// </summary>
        /// <value>An inverse of this instance, if possible; otherwise, a null reference (Nothing in Visual Basic).</value>
        public abstract GeneralTransform3D Inverse 
        { 
            get; 
        }
        #endregion

        #region Methods
        /// <summary>
        /// Transforms the specified 3-D point and returns the result.
        /// </summary>
        /// <param name="point">The 3-D point to transform.</param>
        /// <returns>The result of transforming point.</returns>
        public Point3D Transform(Point3D point)
        {
            Point3D newPoint = new Point3D();
            if (this.TryTransform(point, out newPoint))
            {
                return newPoint;
            }
            else
            {
                throw new InvalidOperationException("The transform did not succeed.");
            }
        }

        /// <summary>
        /// When overridden in a derived class, attempts to transform the specified 3-D point and returns a value that indicates whether the transformation was successful.
        /// </summary>
        /// <param name="inPoint">The 3-D point to transform.</param>
        /// <param name="result">The 3-D point to transform.</param>
        /// <returns>true if inPoint was transformed; otherwise, false.</returns>
        /// <remarks>Unlike the Transform method, this method does not throw an exception if the transformation is unsuccessful.</remarks>
        public abstract bool TryTransform(Point3D inPoint, out Point3D result);

        /// <summary>
        /// When overridden in a derived class, transforms the specified 3-D bounding box and returns an axis-aligned 3-D bounding box that is exactly large enough to contain it.
        /// </summary>
        /// <param name="rect">The 3-D bounding box to transform.</param>
        /// <returns>The smallest axis-aligned 3-D bounding box possible that contains the transformed rect.</returns>
        public abstract Rect3D TransformBounds(Rect3D rect);
        #endregion
        
        #region IFormattable Members

        public string ToString(string format, IFormatProvider formatProvider)
        {
            return this.ToString();
        }

        #endregion
    }
}
